﻿// -----------------------------------------------------------------------
// <copyright file="CustomerEditVIewModel.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ModuleCustomerEdit.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ModulesInfrastructure.ViewModels;
    using ServerConnection.ShopServiceReference;
    using System.ComponentModel;
using ModuleCustomerEdit.Commands;
    using Microsoft.Practices.Prism.Events;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CustomerEditViewModel : SharedViewModel, ICustomerEditViewModel
    {
        private User _user;

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        public void Load(User user)
        {
            _user = user;
            this.PropertyChanged(this, new PropertyChangedEventArgs("User"));
        }

        public User User
        {
            get
            {
                return _user;
            }
        }

        public CustomerEditViewModel()
        {
            m_cmdOkClickCommand = new OkClickCommand();
            m_cmdCancelClickCommand = new CancelClickCommand();
        }

        public Dictionary<int, string> Places
        {
            get
            {
                Dictionary<int, string> result = new Dictionary<int, string>();

                PlaceView[] list = ServerConnection.Service.Instance.GetPlaces("eng");
                if (list != null)
                {
                    result.Clear();
                    foreach (var item in list)
                    {
                        result.Add(item.Id, item.Name);
                    }
                }

                return result;
            }
        }

        public Dictionary<UserRole, string> Roles
        {
            get
            {
                Dictionary<UserRole, string> result = new Dictionary<UserRole, string>();
                result.Add(UserRole.Manager, "Manager");
                if (ServerConnection.Service.PlaceId == 0)
                {
                    result.Add(UserRole.Administrator, "Administrator");
                }
                result.Add(UserRole.Storekeeper, "Storekeeper");
                result.Add(UserRole.Banned, "Banned");
                return result;
            }
        }

        private OkClickCommand m_cmdOkClickCommand;

        public OkClickCommand OkClickCommand
        {
            get
            {
                return m_cmdOkClickCommand;
            }
        }

        private CancelClickCommand m_cmdCancelClickCommand;

        public CancelClickCommand CancelClickCommand
        {
            get
            {
                return m_cmdCancelClickCommand;
            }
        }
        
    }
}
